package com.itcast.peft.controller;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.itcast.peft.service.InteractionDataWasher;
import com.itcast.peft.service.InteractionService;

@RestController
@RequestMapping("/interaction")
public class InteractionController {

    @Autowired
    private InteractionService interactionService;
    
    @Autowired
    private InteractionDataWasher interactionDataWasher;
    
    
    @GetMapping("/dataGenerate")
    @ResponseBody
    public String dataGenerate() {
        interactionService.dataGenerate();
        return "success";
    }
    
    @GetMapping("/dataWash")
    @ResponseBody
    public String dataWash(@RequestParam(required = false, defaultValue = "2025-07-31T19:00:00") String startTime) {
        interactionDataWasher.dataWash(startTime);
        return "success";
    }
    
    @PostMapping("/importQuestion")
    @ResponseBody
    public String importQuestion(@RequestParam("file") MultipartFile file) throws IOException {
        interactionService.importQuestion(new String(file.getBytes(),StandardCharsets.UTF_8));
        return "success";
    }
    
    @PostMapping("/importReply")
    @ResponseBody
    public String importReply(@RequestParam("file") MultipartFile file) throws IOException {
        interactionService.importReply(new String(file.getBytes(),StandardCharsets.UTF_8));
        return "success";
    }
}
